
const _interopRequireDefault = require('@babel/runtime/helpers/interopRequireDefault');

exports.__esModule = true;
exports.default = void 0;

const _babelHelperVueJsxMergeProps = _interopRequireDefault(require('@vue/babel-helper-vue-jsx-merge-props'));

const _utils = require('../utils');

const _functional = require('../utils/functional');

const _icon = _interopRequireDefault(require('../icon'));

const _button = _interopRequireDefault(require('../button'));

// Utils
// Components
const _createNamespace = (0, _utils.createNamespace)('submit-bar');
const createComponent = _createNamespace[0];
const bem = _createNamespace[1];
const t = _createNamespace[2];

function SubmitBar(h, props, slots, ctx) {
  const { tip } = props;
  const { price } = props;
  const { tipIcon } = props;

  function Text() {
    if (typeof price === 'number') {
      const priceArr = (price / 100).toFixed(props.decimalLength).split('.');
      const decimalStr = props.decimalLength ? `.${priceArr[1]}` : '';
      return h('div', {
        style: {
          textAlign: props.textAlign ? props.textAlign : '',
        },
        class: bem('text'),
      }, [h('span', [props.label || t('label')]), h('span', {
        class: bem('price'),
      }, [props.currency, h('span', {
        class: bem('price', 'integer'),
      }, [priceArr[0]]), decimalStr]), props.suffixLabel && h('span', {
        class: bem('suffix-label'),
      }, [props.suffixLabel])]);
    }
  }

  function Tip() {
    if (slots.tip || tip) {
      return h('div', {
        class: bem('tip'),
      }, [tipIcon && h(_icon.default, {
        class: bem('tip-icon'),
        attrs: {
          name: tipIcon,
        },
      }), tip && h('span', {
        class: bem('tip-text'),
      }, [tip]), slots.tip && slots.tip()]);
    }
  }

  return h('div', (0, _babelHelperVueJsxMergeProps.default)([{
    class: bem({
      unfit: !props.safeAreaInsetBottom,
    }),
  }, (0, _functional.inherit)(ctx)]), [slots.top && slots.top(), Tip(), h('div', {
    class: bem('bar'),
  }, [slots.default && slots.default(), Text(), h(_button.default, {
    attrs: {
      round: true,
      type: props.buttonType,
      loading: props.loading,
      disabled: props.disabled,
      text: props.loading ? '' : props.buttonText,
    },
    class: bem('button', props.buttonType),
    on: {
      click: function click() {
        (0, _functional.emit)(ctx, 'submit');
      },
    },
  })])]);
}

SubmitBar.props = {
  tip: String,
  label: String,
  price: Number,
  tipIcon: String,
  loading: Boolean,
  disabled: Boolean,
  textAlign: String,
  buttonText: String,
  suffixLabel: String,
  safeAreaInsetBottom: {
    type: Boolean,
    default: true,
  },
  decimalLength: {
    type: [Number, String],
    default: 2,
  },
  currency: {
    type: String,
    default: '¥',
  },
  buttonType: {
    type: String,
    default: 'danger',
  },
};

const _default = createComponent(SubmitBar);

exports.default = _default;
